<?php 
    
    $tmpedit = new XTemplate('sites/views/hocsinh/edit.html');
    $id = $_GET['id'];
    $sql = "SELECT * FROM hocsinh WHERE id=".$id;
    $arr = $db->GetRow($sql);
    $ngaysinh = date('d/m/Y', strtotime($arr['ngaysinh']));
    $mahs = $arr['mahs'];
    $gioitinh = selectGT($arr['gioitinh']);
    $name = $arr['fullname'];
    $avatar = $arr['avatar'];
    if($_POST){
        $name = $_POST['fullname'];
        $ngaysinh = date('Y-m-d 00:00:00',strtotime($_POST['ngaysinh']));
        $mahs = $_POST['mahs'];
        $gioitinh = $_POST['gender'];
        //-----------------------------
        $avatar = $_FILES["file"]["name"];
        $url='asset/image/';
        move_uploaded_file($_FILES["file"]["tmp_name"],$url . $_FILES["file"]["name"]);
        //die('xxxxxxxxxxxxxx');
        //-----------------------------
       // print_r($_POST);die;
        if(!name){
            
            $save =-1;
            echo "<script>alert('khong duoc bo trong')</script>";
        }
        if(!$cmnd){
            $save = -1;
            echo "<script>alert('khong duoc bo trong')</script>";
        }
        if($save != -1){
            $sql = "UPDATE hocsinh SET fullname = '$name',ngaysinh='$ngaysinh',mahs='$mahs',gioitinh='$gioitinh', avatar = '$avatar' WHERE id=".$id;
            $db->Execute($sql);
               header("Location: index.php?m=hocsinh&act=list");
        }
    }
   // print_r($arr);
    $tmpedit->assign('avatar',$avatar);
    $tmpedit->assign('fullname',$name);
    $tmpedit->assign('ngaysinh',$ngaysinh);
    $tmpedit->assign('mahs',$mahs);
    $tmpedit->assign('gioitinh',$gioitinh);
    $tmpedit->parse('HSEDIT');
    $maincontent = $tmpedit->text('HSEDIT');
?>